# coding=utf-8
import threading

from DataBase.SQLiteObject import SQLiteObject
from DataBase.MysqlObject import MySQLObject


class DBObject:

    _instance_lock = threading.Lock()
    dbObject = None

    def __init__(self, type='sqlite'):
        if type == 'sqlite':
            self.dbObject = SQLiteObject()
        elif type == 'mysql':
            self.dbObject = MySQLObject()

    def get_db_operator(self):
        return self.dbObject
    
    @classmethod
    def instance(cls, type='sqlite'):
        if not hasattr(DBObject, "_instance"):
            with DBObject._instance_lock:
                if not hasattr(DBObject, "_instance"):
                    DBObject._instance = DBObject(type=type)
        return DBObject._instance
